<div id="content" class="span12">
    <h1>Groups</h1>

    <div class="row">
        <div id="sidebar" class="span8">
            <div class="btn-toolbar">
                <div class="btn-group">
                    <?php echo CHtml::link('Group Entry', '#dialog', array('class' => 'btn btn-info', 'data-toggle' => 'modal', 'onClick' => 'addGroup();')); ?>
                </div>
            </div>
        </div>
        <div class="span12">
            <?php
            $this->widget('zii.widgets.grid.CGridView', array(
                'id' => 'data-grid',
                'dataProvider' => $dataProvider,
                //'filter' => $model,
                'columns' => array(
                    array(
                        'name' => 'id',
                        'header' => 'ID',
                    ),
                    array(
                        'name' => 'name',
                        'header' => 'Group Name',
                    ),
                    array(
                        'name' => 'create_date',
                        'header' => 'Date Added',
                        'value' => 'Yii::app()->dateFormatter->format("MMMM d, yyyy (EEEE)", $data->create_date)',
                    ),
                    array(
                        'name' => 'last_broadcast_time',
                        'header' => 'Last Broadcast Time',
                        'value' => '($value = $data->last_broadcast_time) ? Yii::app()->dateFormatter->format("h:mm a - MMM d, yyyy (EEEE)", $value) : "n/a"',
                    ),
                ),
                'cssFile' => false,
                'itemsCssClass' => 'table',
                'summaryCssClass' => 'pull-right',
            ));
            ?>
        </div>    
    </div>
</div>

<script>
    function addGroup() {
<?php
echo CHtml::ajax(array(
    'url' => array('group/create'),
    'data' => 'js:$(this).serialize()',
    'type' => 'post',
    'dataType' => 'json',
    'success' => 'function(data) {
                if (data.status == "failure")
                {
                    $("#dialog").html(data.div);
                    $("#dialog form").submit(addGroup);
                }
                else
                {
                    $("#dialog").html(data.div);
                    setTimeout("$(\"#dialog\").dialog(\"hide\")",3000);
                }
            }'
));
?>
        return false;
    }
</script>